package com.ocean.productDict.service.impl;

import java.util.*;

import com.ocean.common.core.domain.entity.SysUser;
import com.ocean.common.utils.ShiroUtils;
import com.ocean.common.utils.uuid.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ocean.productDict.mapper.OForecastElementMapper;
import com.ocean.productDict.domain.OForecastElement;
import com.ocean.productDict.service.IOForecastElementService;
import com.ocean.common.core.text.Convert;

/**
 * 要素维护Service业务层处理
 *
 * @author ocean
 * @date 2023-01-03
 */
@Service
public class OForecastElementServiceImpl implements IOForecastElementService
{
    @Autowired
    private OForecastElementMapper oForecastElementMapper;

    /**
     * 查询要素维护
     *
     * @param id 要素维护主键
     * @return 要素维护
     */
    @Override
    public OForecastElement selectOForecastElementById(String id)
    {
        return oForecastElementMapper.selectOForecastElementById(id);
    }

    /**
     * 查询要素维护列表
     *
     * @param oForecastElement 要素维护
     * @return 要素维护
     */
    @Override
    public List<OForecastElement> selectOForecastElementList(OForecastElement oForecastElement)
    {
        return oForecastElementMapper.selectOForecastElementList(oForecastElement);
    }

    /**
     * 新增要素维护
     *
     * @param oForecastElement 要素维护
     * @return 结果
     */
    @Override
    public int insertOForecastElement(OForecastElement oForecastElement)
    {
        oForecastElement.setId(IdUtils.simpleUUID());
        SysUser sysUser = ShiroUtils.getSysUser();
        oForecastElement.setCreateName(sysUser.getUserName());
        oForecastElement.setCreateBy(sysUser.getLoginName());
        oForecastElement.setCreateDate(new Date());
        oForecastElement.setUpdateName(sysUser.getUserName());
        oForecastElement.setUpdateBy(sysUser.getLoginName());
        oForecastElement.setUpdateDate(new Date());
        oForecastElement.setDepartId(sysUser.getDeptId().toString());
        return oForecastElementMapper.insertOForecastElement(oForecastElement);
    }

    /**
     * 修改要素维护
     *
     * @param oForecastElement 要素维护
     * @return 结果
     */
    @Override
    public int updateOForecastElement(OForecastElement oForecastElement)
    {
        SysUser sysUser = ShiroUtils.getSysUser();
        oForecastElement.setUpdateName(sysUser.getUserName());
        oForecastElement.setUpdateBy(sysUser.getLoginName());
        oForecastElement.setUpdateDate(new Date());
        return oForecastElementMapper.updateOForecastElement(oForecastElement);
    }

    /**
     * 批量删除要素维护
     *
     * @param ids 需要删除的要素维护主键
     * @return 结果
     */
    @Override
    public int deleteOForecastElementByIds(String ids)
    {
        return oForecastElementMapper.deleteOForecastElementByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除要素维护信息
     *
     * @param id 要素维护主键
     * @return 结果
     */
    @Override
    public int deleteOForecastElementById(String id)
    {
        return oForecastElementMapper.deleteOForecastElementById(id);
    }

    @Override
    public Map<String, List> getNameAndCode() {
        Map<String, List> result = new HashMap<>();
        List<OForecastElement> list = oForecastElementMapper.selectOForecastElementList(new OForecastElement());
        List<String> names = new ArrayList<>();
        List<String> codes = new ArrayList<>();
        for (OForecastElement element : list) {
            names.add(element.getElementName());
            codes.add(element.getEnglishAbbreviations());
        }
        result.put("names",names);result.put("codes",codes);
        return result;
    }

    @Override
    public List<OForecastElement> getAllForecastElement() {
        return oForecastElementMapper.getAllForecastElement();
    }
}
